//
//  BmbViewController.m
//  InSuger
//
//  Created by dllo on 15/12/7.
//  Copyright © 2015年 Dior_3g. All rights reserved.
//

#import "BmbViewController.h"
#import "AppDelegate.h"
@interface BmbViewController ()<UIScrollViewDelegate>
@property(nonatomic, strong) UIScrollView *scrollView;
@property(nonatomic, strong) NSArray *picArr;
@property(nonatomic, strong) UIPageControl *page;
@end

@implementation BmbViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.picArr = @[@"1.png", @"2.jpg", @"3.png"];
    [self createScrollView];
    [self pageCreateData];
}

- (void)pageCreateData
{
    //  创建一个pageControl
    self.page = [[UIPageControl alloc]initWithFrame:CGRectMake(100, 600, 200, 40)];
    [self.view addSubview:self.page];
    self.page.numberOfPages = 3;
    //      页面指示器色调的颜色  设置未被点的颜色
    self.page.pageIndicatorTintColor  = [UIColor redColor];
    //      当前页面指示器色调的颜色  选中的点得颜色
    self.page.currentPageIndicatorTintColor = [UIColor purpleColor];
   
}



- (void)createScrollView
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    _scrollView.contentSize = CGSizeMake(WIDTH * _picArr.count, 0);
    _scrollView.pagingEnabled = YES;
    [self.view addSubview:_scrollView];
    _scrollView.delegate = self;
    
    
    for (NSInteger i = 0; i < 3; i++ ) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * i, 0, WIDTH, HEIGHT)];
        imageView.image = [UIImage imageNamed:_picArr[i]];
        [_scrollView addSubview:imageView];
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offsetX = self.scrollView.contentOffset.x;
    if (offsetX > WIDTH * 2) {
        
        AppDelegate *appVC = (AppDelegate *)[[UIApplication sharedApplication]delegate];
        [[UIApplication sharedApplication].keyWindow setRootViewController:appVC.tab];
    }
    self.page.currentPage = self.scrollView.contentOffset.x / WIDTH ;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
